package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.entities.CommomResult;
import com.atguigu.springcloud.entities.Payment;
import com.atguigu.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Slf4j
public class PaymentController {

    @Resource
    private PaymentService paymentService;

    @PostMapping(value = "/payment/create")
    public CommomResult create(@RequestBody Payment payment){
        int result=paymentService.insertPayment(payment);
        log.info("***插入结果"+result);

        if (result>0){
            return  new CommomResult(200,"插入数据库成功",result);
        }else {
            return new CommomResult(444,"插入数据库失败",result);
        }



    }


    @GetMapping(value = "/payment/get/{id}")
    public CommomResult getpaymentbyid(@PathVariable("id") Long id){
        Payment payment = paymentService.selectpaymentById(id);
        log.info("***插入结果"+payment+"sss");
        System.out.println(payment);

        if (payment!=null){
            return  new CommomResult(200,"查询成功",payment);
        }else {
            return new CommomResult(444,"没有对应记录,对应"+id);
        }

    }

    @DeleteMapping(value = "/payment/delete/{id}")
    public CommomResult delpaymentbyid(@PathVariable("id") Long id){
        int result= paymentService.delpaymentById(id);
        log.info("***删除结果"+result);
        if (result>0){
            return  new CommomResult(200,"删除成功",result);
        }else {
            return new CommomResult(444,"删除失败",result);
        }

    }







}
